package com.room.search.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.room.search.domain.vo.AbstractAuditingBuilderEntity;
import org.hibernate.annotations.BatchSize;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 投诉建议
 */
@Entity
@Table(name = "room_user")
@org.springframework.data.elasticsearch.annotations.Document(indexName = "room_user")
public class RoomUser extends AbstractAuditingBuilderEntity<RoomUser> {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Size(max = 50)
    @Column(name = "nick_name", length = 50)
    private String nickName;

    @NotNull
    @Size(max = 30)
    @Column(name = "account", length = 30, nullable = false)
    private String account;

    @NotNull
    @Size(max = 60)
    @Column(name = "password", length = 60, nullable = false)
    private String password;

    @Size(max = 11)
    @Column(name = "mobile", length = 11)
    private String mobile;

    @Column(name = "avatar")
    private String avatar;

    @Column(name = "slogan")
    private String slogan;

    @NotNull
    @Column(name = "activated")
    private boolean activated;

    @JsonIgnore
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(
        name = "room_user_authority",
        joinColumns = {@JoinColumn(name = "room_user_id", referencedColumnName = "id")},
        inverseJoinColumns = {@JoinColumn(name = "authority_name", referencedColumnName = "name")}
    )
    @BatchSize(size = 20)
    private Set<Authority> authorities = new HashSet<>();

    @ManyToMany(mappedBy = "roomUsers")
    @JsonIgnore
    private Set<RoomGoods> roomGoods = new HashSet<>();


    @JsonIgnore
    @ManyToMany
    @JoinTable(
        name = "room_community_user",
        joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
        inverseJoinColumns = {@JoinColumn(name = "community_id", referencedColumnName = "id")}
    )
    private Set<RoomCommunity> roomCommunities = new HashSet<>();

    @Column(name = "perms")
    private String perms;


    @Column(name = "sys")
    private Boolean sys;

    @Column(name = "broker")
    private Boolean broker;

    /**
     * 省份
     */
    @Column(name = "province")
    private String province;
    /**
     * 市区
     */
    @Column(name = "city")
    private String city;
    /**
     * 区县
     */
    @Column(name = "district")
    private String district;

    public String getProvince() {
        return province;
    }

    public RoomUser setProvince(String province) {
        this.province = province;
        return this;
    }

    public String getCity() {
        return city;
    }

    public RoomUser setCity(String city) {
        this.city = city;
        return this;
    }

    public String getDistrict() {
        return district;
    }

    public RoomUser setDistrict(String district) {
        this.district = district;
        return this;
    }

    public Boolean getBroker() {
        return broker;
    }

    public RoomUser setBroker(Boolean broker) {
        this.broker = broker;
        return this;
    }

    public Set<Authority> getAuthorities() {
        return authorities;
    }

    public RoomUser setAuthorities(Set<Authority> authorities) {
        this.authorities = authorities;
        return this;
    }

    public boolean isActivated() {
        return activated;
    }

    public RoomUser setActivated(boolean activated) {
        this.activated = activated;
        return this;
    }

    // jhipster-needle-entity-add-field - JHipster will add fields here

    public Long getId() {
        return this.id;
    }

    public RoomUser id(Long id) {
        this.setId(id);
        return this;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNickName() {
        return this.nickName;
    }

    public RoomUser nickName(String nickName) {
        this.setNickName(nickName);
        return this;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getAccount() {
        return this.account;
    }

    public RoomUser account(String account) {
        this.setAccount(account);
        return this;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return this.password;
    }

    public RoomUser password(String password) {
        this.setPassword(password);
        return this;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getMobile() {
        return this.mobile;
    }

    public RoomUser mobile(String mobile) {
        this.setMobile(mobile);
        return this;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getAvatar() {
        return this.avatar;
    }

    public RoomUser avatar(String avatar) {
        this.setAvatar(avatar);
        return this;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getSlogan() {
        return this.slogan;
    }

    public RoomUser slogan(String slogan) {
        this.setSlogan(slogan);
        return this;
    }

    public void setSlogan(String slogan) {
        this.slogan = slogan;
    }

    public Set<RoomGoods> getRoomGoods() {
        return roomGoods;
    }

    public RoomUser setRoomGoods(Set<RoomGoods> roomGoods) {
        this.roomGoods = roomGoods;
        return this;
    }

    public Set<RoomCommunity> getRoomCommunities() {
        return roomCommunities;
    }

    public RoomUser setRoomCommunities(Set<RoomCommunity> roomCommunities) {
        this.roomCommunities = roomCommunities;
        return this;
    }

    public String getPerms() {
        return perms;
    }

    public RoomUser setPerms(String perms) {
        this.perms = perms;
        return this;
    }

    public Boolean getSys() {
        return sys;
    }

    public RoomUser setSys(Boolean sys) {
        this.sys = sys;
        return this;
    }


    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof RoomUser)) {
            return false;
        }
        return id != null && id.equals(((RoomUser) o).id);
    }

    @Override
    public int hashCode() {
        // see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
        return getClass().hashCode();
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "RoomUser{" +
            "id=" + getId() +
            ", nickName='" + getNickName() + "'" +
            ", account='" + getAccount() + "'" +
            ", password='" + getPassword() + "'" +
            ", mobile='" + getMobile() + "'" +
            ", avatar='" + getAvatar() + "'" +
            ", slogan='" + getSlogan() + "'" +
            "}";
    }
}
